#!/bin/bash
set -e
PATH=$PATH:/usr/lib/jvm/default-jvm/bin/ #:/data/apache-storm-2.3.0/bin
export PATH

cd /data

jar -xvf surge-deploy-pradar-storm.jar deploy.properties

sed -i -e "s/config.data.zk.servers=.*/config.data.zk.servers=$ZK_HOSTS/g" deploy.properties

sed -i -e "s/config.influxdb.url=.*/config.influxdb.url=http:\/\/$INFLUXDB_HOST/g" deploy.properties

sed -i -e "s/config.influxdb.username=.*/config.influxdb.username=$INFLUXDB_USERNAME/g" deploy.properties

sed -i -e "s/config.influxdb.password=.*/config.influxdb.password=$INFLUXDB_PASSWORD/g" deploy.properties

sed -i -e "s/tro.url.ip=pradar.host.troweb/tro.url.ip=$TRO_WEB_HOST/g" deploy.properties

sed -i -e "s/amdb.url.ip=pradar.host.amdb/amdb.url.ip=${AMDB_HOST}/g" deploy.properties

sed -i -e "s/config.clickhouse.url=.*/config.clickhouse.url=jdbc:clickhouse:\/\/$CLICKHOUSE_HOST\/default/g" deploy.properties

sed -i -e "s/config.clickhouse.userName=.*/config.clickhouse.userName=$CLICKHOUSE_USERNAME/g" deploy.properties

sed -i -e "s/config.clickhouse.password=.*/config.clickhouse.password=$CLICKHOUSE_PASSWORD/g" deploy.properties

sed -i -e "s/config.mysql.url=.*/config.mysql.url=jdbc:mysql:\/\/$MYSQL_HOST\/amdb?useUnicode=true\&characterEncoding=UTF-8\&useSSL=false\&allowMultiQueries=true\&serverTimezone=GMT%2B8/g" deploy.properties

sed -i -e "s/config.mysql.userName=.*/config.mysql.userName=$MYSQL_USERNAME/g" deploy.properties

sed -i -e "s/config.mysql.password=.*/config.mysql.password=$MYSQL_PASSWORD/g" deploy.properties

sed -i -e "s/netty.remoting.server.processCores=.*/netty.remoting.server.processCores=$PROCESSCORES/g" deploy.properties

cat deploy.properties

jar -uvf surge-deploy-pradar-storm.jar deploy.properties

java -XX:MaxRAMPercentage=90.0 -Xmx$MEMORY -Xms$MEMORY -Xss1m -cp surge-deploy-pradar-storm.jar io.shulie.surge.data.deploy.pradar.bootstrap.PradarTopologyBootStrap -DSourceType=$SOURCE_TYPE -DWorkers=$PROCESSCORES -DNet={\"$INTRAIP\":\"$OUTERIP\"}
# storm -XX:MaxRAMPercentage=90.0 -Xms512m jar surge-deploy-pradar-storm.jar io.shulie.surge.data.deploy.pradar.bootstrap.PradarTopologyBootStrap -DSourceType=$SOURCE_TYPE -DWorkers=$PROCESSCORES -DNet={\"$INTRAIP\":\"$OUTERIP\"}
